package cn.tedu.spring.iocxml;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UserTest {

    //1.根据id属性值获取bean对象
    @Test
    public void idTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        User user = (User) context.getBean("user2");
        user.run();
    }

    //2.根据类型获取bean对象
    @Test
    public void classTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        User user = (User) context.getBean(User.class);
        user.run();
    }
    //3.根据id属性值和类型class获取bean对象
    @Test
    public void idClassTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        User user = (User) context.getBean("user2", User.class);
        user.run();
    }
}
